import { Component } from 'react';
import styles from './PrChild1.module.scss';
import { globalContext } from './global';
const { Consumer } = globalContext;
class PrChild extends Component {
  static contextType = globalContext;
  state = {};
  render() {
    console.log(this.context, '子组件1');
    const { data1, updateData1 } = this.props;
    return (
      <div className={styles.prchild1}>
        4445
        <h1>子组件1</h1>
        <u>{data1}</u>
        <Consumer>
          {(e) => (
            <h1>
              子组件通过consumer获取共享数据：{e.name},{e.email}
            </h1>
          )}
        </Consumer>
        <button onClick={() => updateData1('子组件修改了父组件的数据')}>
          修改父组件传过来的数据
        </button>
      </div>
    );
  }
}

export default PrChild;
